
/**
* @module Log
* @author: guojianbo
* @description: 对日志的封装。logan接入文档：https://docs.sankuai.com/dp/yayajing/logan-web/master/user-config/#loganloglogstring-logtype
* @since: 2021-07-21 17:35:34
*/
Object.defineProperty(exports, "__esModule", { value: true });
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var Log = /** @class */ (function () {
    function Log() {
        this.mIsInit = false;
        this.Logan = null;
        this.mCloseConsoleLog = false;
    }
    // test() {
    //     this.log('test::log')
    //     this.log('test::log', 'test::log2')
    //     this.info('test::info')
    //     this.info('test::info', 'test::info2')
    //     this.warn('test::warn')
    //     this.warn('test::warn', 'test::warn2')
    //     this.error('test::error')
    //     this.error('test::error', 'test::error2')
    //     this.report()
    // }
    Log.prototype.getLogPrintInfo = function (args) {
        try {
            if (!args || args.length <= 0) {
                console.log('Log::getLogPrintInfo not found args');
                return [''];
            }
            if (args.length > 1) {
                args.push(Log.SDK_LOG_TAG);
                return args;
            }
            if (typeof args[0] !== 'string') {
                args.push(Log.SDK_LOG_TAG);
                return args;
            }
            var logString = (Log.SDK_LOG_TAG + args[0]);
            if (logString.length > Log.SDK_LOG_MAX_WRITE_COUNT) {
                logString = logString.substring(0, Log.SDK_LOG_MAX_WRITE_COUNT);
            }
            return [logString];
        }
        catch (error) {
            console.log('Log::getLogPrintInfo info:' + error);
        }
        return [''];
    };
    Log.prototype.getLoganPrintInfo = function (args) {
        try {
            if (!args || args.length <= 0) {
                console.log('Log::getLoganPrintInfo not found args');
                return '';
            }
            var ret = '';
            for (var i = 0; i < args.length; i++) {
                ret += args[i].toString();
                if (i != (args.length - 1)) {
                    ret += ' ';
                }
            }
            return ret;
        }
        catch (error) {
            console.log('Log::getLoganPrintInfo info:' + error);
        }
        return '';
    };
    Log.prototype.init = function (loganObject, closeConsoleLog) {
        try {
            if (this.mIsInit) {
                return;
            }
            this.mCloseConsoleLog = closeConsoleLog ? closeConsoleLog : false;
            if (loganObject) {
                if (false) {}
                else {
                    if (!loganObject.log || !loganObject.info || !loganObject.warn || !loganObject.error || !loganObject.report) {
                        this.log('Log::init not found logan function');
                    }
                    else {
                        this.Logan = loganObject;
                        this.log('Log::init set logan object');
                    }
                }
            }
            else {
                this.log('Log::init not found logan object');
            }
            this.mIsInit = true;
        }
        catch (error) {
            this.error('Log::init exception::' + error);
        }
    };
    Log.prototype.log = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            var logInfo = this.getLogPrintInfo(args);
            if (!this.mCloseConsoleLog) {
                console.log.apply(console, logInfo);
            }
            if (this.Logan) {
                if (false) {}
                else {
                    if (this.Logan.log) {
                        this.Logan.log(this.getLoganPrintInfo(logInfo));
                    }
                }
            }
        }
        catch (error) {
            console.log('Log::log info:' + error);
        }
    };
    Log.prototype.info = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            var logInfo = this.getLogPrintInfo(args);
            if (!this.mCloseConsoleLog) {
                console.info.apply(console, logInfo);
            }
            if (this.Logan) {
                if (false) {}
                else {
                    if (this.Logan.info) {
                        this.Logan.info(this.getLoganPrintInfo(logInfo));
                    }
                }
            }
        }
        catch (error) {
            console.log('Log::info info:' + error);
        }
    };
    Log.prototype.warn = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            var logInfo = this.getLogPrintInfo(args);
            if (!this.mCloseConsoleLog) {
                console.warn.apply(console, logInfo);
            }
            if (this.Logan) {
                if (false) {}
                else {
                    if (this.Logan.warn) {
                        this.Logan.warn(this.getLoganPrintInfo(logInfo));
                    }
                }
            }
        }
        catch (error) {
            console.log('Log::warn info:' + error);
        }
    };
    Log.prototype.error = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        try {
            var logInfo = this.getLogPrintInfo(args);
            if (!this.mCloseConsoleLog) {
                console.error.apply(console, logInfo);
            }
            if (this.Logan) {
                if (false) {}
                else {
                    if (this.Logan.error) {
                        this.Logan.error(this.getLoganPrintInfo(logInfo));
                    }
                }
            }
        }
        catch (error) {
            console.log('Log::error info:' + error);
        }
    };
    Log.prototype.report = function (callback) {
        try {
            if (this.Logan) {
                var that_1 = this;
                var unionId_1 = 'imsdk_' + (userData_1.default.get('appId') || '0') + '_' + (userData_1.default.get('uid') || '0')
                    + '_' + (userData_1.default.get('deviceId') || '0');
                this.log('Log::report log unionId:' + unionId_1);
                if (false) {}
                else {
                    if (this.Logan.report) {
                        this.Logan.report(null, null, {
                            unionId: unionId_1,
                            customReport: {},
                            onReportFinished: function (reportResult) {
                                that_1.log('Log::report result unionId:' + unionId_1 + ' info:' + JSON.stringify(reportResult));
                                if (callback) {
                                    callback({ unionId: unionId_1, result: 0 });
                                }
                            }
                        });
                    }
                }
            }
        }
        catch (error) {
            console.log('Log::report info:' + error);
        }
    };
    Log.SDK_LOG_TAG = 'IMSDK::';
    Log.SDK_LOG_MAX_WRITE_COUNT = 10000;
    return Log;
}());
exports.default = new Log();


//# sourceURL=webpack://MTDX/./src/core/utils/log.ts?